type Optional<T> = T | null | undefined;

export interface BillingStatus {
  value: string;
  name: string;
  translate?: string;
}

export const BillingStatuses: BillingStatus[] = [
  {
    value: 'PENDING',
    name: '待审核'
  },
  {
    value: 'APPROVAL',
    name: '待转账'
  },
  {
    value: 'COMPLETED',
    name: '完成'
  },
  {
    value: 'FAILED',
    name: '失败'
  },
  {
    value: 'REJECTED',
    name: '拒绝'
  },
  {
    value: 'CANCELED',
    name: '取消'
  },
  { value: 'RECHARGE_WAITING', name: '待确认' },
  { value: 'RECHARGE_EXPIRED', name: '充值关闭' },
  { value: 'RECHARGE_SUCCESS', name: '充值成功' },
  { value: 'RECHARGE_UNUSUAL', name: '充值异常' }
];

export function getBillingStatusByName(name: string): Optional<BillingStatus> {
  const index = BillingStatuses.findIndex(bt => bt.name === name);
  if (index > -1) {
    return BillingStatuses[index];
  } else {
    return null;
  }
}

export function getBillingStatusByValue(value: string): Optional<BillingStatus> {
  const index = BillingStatuses.findIndex(bt => bt.value === value);
  if (index > -1) {
    return BillingStatuses[index];
  } else {
    return null;
  }
}
